<?php
# idxCMS Flat Files Content Management System v5.0
# Copyright (c) 2011-2016 Victor Nabatov greenray.spb@gmail.com
# Module USER: Feedback

if (!defined('idxCMS')) die();

$message = '';
#
# Here the desired filtering, but now we have another problem.
# Filter, you know how.
#
if (!empty($REQUEST['text'])) {
    try {
        CheckCaptcha();
        $FEEDBACK = new MESSAGE(CONTENT, 'feedback');
        $FEEDBACK->sendFeedback(
            $REQUEST['text'],
            empty($REQUEST['email']) ? USER::getUser('email') : $REQUEST['email'],
            empty($REQUEST['name'])  ? USER::getUser('nick')  : $REQUEST['name']
        );
        $message = SYSTEM::showMessage('message', 'Message sent');

        unset($REQUEST);
        unset($FEEDBACK);

    } catch (Exception $error) {
        $message = SYSTEM::showMessage('error', $error->getMessage());
    }
}

$TEMPLATE = new TEMPLATE(__DIR__.DS.'feedback');

if (!USER::$logged_in) {
    $TEMPLATE->set('name',  empty($REQUEST['name'])  ? '' : $REQUEST['name']);
    $TEMPLATE->set('email', empty($REQUEST['email']) ? '' : $REQUEST['email']);
    $TEMPLATE->set('captcha', ShowCaptcha());
}
$TEMPLATE->set('logged_in', USER::$logged_in);
$TEMPLATE->set('text', empty($REQUEST['text']) ? '' : $REQUEST['text']);
$TEMPLATE->set('message_length', USER::$root ? NULL : CONFIG::getValue('feedback', 'message_length'));
$TEMPLATE->set('bbcodes', CMS::call('PARSER')->showBbcodesPanel('feedback.text'));
if (!empty($message)) $TEMPLATE->set('message', $message);

SYSTEM::set('pagename', __('Feedback'));
SYSTEM::defineWindow('Feedback', $TEMPLATE->parse());
